package cn.nexd.location.indoor.core.mathematician;

import java.util.List;

import cn.nexd.location.indoor.bean.IndoorLocationData;

/**
 * Created by codngfish on 16/5/24.
 */
public class NexdIndoorWifiExtractor {

    public static double[] extractWifi(String[] wifiList, List<IndoorLocationData> indoorLocationDatas) {
        double[] test = new double[wifiList.length];
        for (int i = 0; i < test.length; i++) {
            test[i] = 0.0;
        }

        for (int i = 0; i < indoorLocationDatas.size(); i++) {
            int index = _search_in_array(wifiList, indoorLocationDatas.get(i).getMac());

            if (index != -1L) {
                test[index] = indoorLocationDatas.get(i).getLevel() + 100.0D;
            }
        }
        return test;
    }

    //    public double[] extractWifi(String[] wifilist, String wifi_input) throws JSONException {
    //        double[] test = new double[wifilist.length];
    //        for (int i = 0; i < test.length; i++) {
    //            test[i] = 0.0;
    //        }
    //
    //        JSONObject jsonObject = new JSONObject(wifi_input);
    //        Iterator<String> keyIter = jsonObject.keys();
    //        Double sum = 0.0;
    //        while (keyIter.hasNext()) {
    //            String keyStr = keyIter.next();
    //            String value = jsonObject.getString(keyStr);
    //            //            Log.d("Debug_round1","Wifi Extraction "+keyStr + " with value: "+value);
    //            int index = _search_in_array(wifilist, keyStr);
    //            if (index != -1) {
    //                test[index] = Double.parseDouble(value) + 100.0;
    //                sum += test[index];
    //            }
    //        }
    //        return test;
    //    }

    private static int _search_in_array(String[] list, String target) {
        int ind = -1;
        for (int i = 0; i < list.length; i++) {
            if (list[i].equalsIgnoreCase(target)) {
                ind = i;
                return ind;
            }
        }
        return ind;
    }

}
